package summer.greedy;

import java.util.Arrays;

public class Solution452 {
    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, ((o1, o2) -> {
            if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]);
            else return Integer.compare(o1[1], o2[1]);
        }));
        int res = 1;
        int cover = points[0][1];
        for (int i = 1; i < points.length; i++) {
            if (points[i][0] <= cover) {
                cover = Math.min(cover, points[i][1]);
            } else {
                res++;
                cover = points[i][1];
            }
        }
        return res;
    }
}
